import { compareAsc, distanceInWords } from 'date-fns';
import zh_cn from 'date-fns/locale/zh_cn';

/**
 * 两个时间戳的距离
 * @param time_left 比较的时间戳1
 * @param time_right 比较的时间戳2
 * @example distance_now(time_left,time_right);
 */
export default function distance_now(time_left: number, time_right: number) {
	const flag = compareAsc(time_right, time_left);
	// todo (2.0版本不能出现前和后)
	if (flag === 0) {
		return distanceInWords(time_right, time_left, { locale: zh_cn });
	} else if (flag === 1) {
		return distanceInWords(time_right, time_left, { locale: zh_cn }) + '前';
	} else {
		return distanceInWords(time_right, time_left, { locale: zh_cn }) + '后';
	}
}
